home *** CD-ROM | disk | FTP | other *** search
/ SGI Origin & Onyx2 Patches 1998 May / Origin and Onyx2 System Disk Patches May 1998.img / dist / patchSG0002839.idb / usr / include / sys / buf.h.z / buf.h
C/C++ Source or Header  |  1998-04-01  |  13KB  |  377 lines

  1. /**************************************************************************
  2.  *                                      *
  3.  *          Copyright (C) 1989-1993 Silicon Graphics, Inc.          *
  4.  *                                      *
  5.  *  These coded instructions, statements, and computer programs  contain  *
  6.  *  unpublished  proprietary  information of Silicon Graphics, Inc., and  *
  7.  *  are protected by Federal copyright law.  They  may  not be disclosed  *
  8.  *  to  third  parties  or copied or duplicated in any form, in whole or  *
  9.  *  in part, without the prior written consent of Silicon Graphics, Inc.  *
  10.  *                                      *
  11.  **************************************************************************/
  12. /*    Copyright (c) 1984 AT&T    */
  13. /*      All Rights Reserved      */
  14.  
  15. /*    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T    */
  16. /*    The copyright notice above does not evidence any       */
  17. /*    actual or intended publication of such source code.    */
  18.  
  19. #ifndef __SYS_BUF_H__
  20. #define __SYS_BUF_H__
  21.  
  22. #ident    "$Revision: 3.86 $"
  23. #include <sys/sema.h>
  24. #include <sys/uio.h>
  25.  
  26. struct ktrace;
  27.  
  28. /*
  29.  *    Each buffer in the pool is usually doubly linked into 2 lists:
  30.  *    the device with which it is currently associated (always)
  31.  *    and also on a list of blocks available for allocation
  32.  *    for other use (usually).
  33.  *    The latter list is kept in last-used order, and the two
  34.  *    lists are doubly linked to make it easy to remove
  35.  *    a buffer from one list when it was found by
  36.  *    looking through the other.
  37.  *    A buffer is on the available list, and is liable
  38.  *    to be reassigned to another disk block, if and only
  39.  *    if it is not marked BUSY.  When a buffer is busy, the
  40.  *    available-list pointers can be used for other purposes.
  41.  *    Most drivers use the forward ptr as a link in their I/O active queue.
  42.  *    A buffer header contains all the information required to perform I/O.
  43.  *    Most of the routines which manipulate these things are in fs_bio.c.
  44.  */
  45.  
  46. typedef struct    buf {
  47.     /*
  48.      * These first 4 fields must match the hbuf definition
  49.      * below.  DO NOT CHANGE THEM OR REARRANGE THEM.
  50.      */
  51.     sema_t    b_lock;            /* lock for buffer usage */
  52.     int    b_flags;        /* see defines below */
  53.     struct    buf *b_forw;        /* headed by d_tab of conf.c */
  54.     struct    buf *b_back;        /*  "  */
  55.     struct    buf *av_forw;        /* position on free list, */
  56.     struct    buf *av_back;        /*     if not BUSY */
  57.     dev_t    b_edev;            /* major+minor device name */
  58.     int    b_error;        /* returned after I/O */
  59.     off_t    b_offset;        /* vnode offset (in basic blocks) */
  60.     unsigned b_bcount;        /* transfer count */
  61.     unsigned b_resid;        /* words not transferred after error */
  62.     unsigned b_remain;        /* virt b_bcount for PAGEIO use only */
  63.     unsigned b_bufsize;        /* size in bytes of allocated buffer */
  64.     __psunsigned_t b_sort;        /* key with which to sort on queue */
  65.     union {
  66.         caddr_t b_addr;        /* low order core address */
  67.         int    *b_words;        /* words for clearing */
  68.         struct pfdat *b_pfdat;    /* pointer into b_pages list */
  69.         daddr_t *b_daddr;        /* disk blocks */
  70.     } b_un;
  71.     union {
  72.         struct  proc *proc;        /* process doing physical or swap I/O */
  73.         struct  vnode *vp;        /* object associated with bp */
  74.     } b_obj;
  75.     daddr_t    b_blkno;        /* block # on device */
  76.     clock_t    b_start;        /* request start time */
  77.     struct  pfdat *b_pages;        /* page list for PAGEIO */
  78.     void (*b_relse)(struct buf *);    /* function called by brelse */
  79.     sema_t    b_iodonesema;        /* lock for waiting on I/O done */
  80.     void (*b_iodone)(struct buf *);    /* function called by iodone */
  81.     void    *b_private;        /* for driver's use */
  82.     void    *b_fsprivate;        /* private ptr for file systems */
  83.     void    *b_fsprivate2;        /* private ptr for file systems */
  84.     short    b_pincount;        /* count of times buf is pinned */
  85.     unsigned char b_pin_waiter;    /* someone waiting for unpin? */
  86.     char    b_listid;        /* free list number */
  87.     char    b_ref;            /* # of free trips through freelist */
  88.     char    b_balance;        /* tree balance */
  89.     struct     buf *b_dforw;        /* vnode delwri chain */
  90.     struct     buf *b_dback;        /* vnode delwri chain */
  91.     struct    buf *b_parent;        /* hash parent pointer */
  92.     void    *b_grio_private;    /* private data for grio */
  93.     struct  buf *b_grio_list;    /* list of bps used in grio */
  94.     int    b_flags2;        /* see more defines below */
  95. #ifdef DEBUG    
  96.     struct ktrace    *b_trace;    /* per buffer trace buffer */
  97. #endif    
  98. } buf_t;
  99.  
  100. typedef int     opaque_t;
  101.  
  102. #define b_proc        b_obj.proc
  103. #define b_vp        b_obj.vp
  104.  
  105. #define paddr(X)    (paddr_t)(X->b_un.b_addr)
  106. #define    b_dmaaddr    b_un.b_addr
  107. #define    b_page        b_un.b_pfdat
  108.  
  109. extern    buf_t        *global_buf_table;    /* The buffer pool itself */
  110. extern    buf_t        *bfreelist;        /* head of available list */
  111. extern    int        bfreelistmask;        /* mask for freelist nums */
  112. struct    pfree    {
  113.     int    b_flags;
  114.     struct    buf    *av_forw;
  115.     struct    buf    *av_back;
  116. };
  117.  
  118. /*
  119.  *    These flags are kept in b_flags.
  120.  */
  121. #define B_WRITE    0x00000000    /* non-read pseudo-flag */
  122. #define B_READ     0x00000001    /* read when I/O occurs */
  123. #define B_DONE     0x00000002    /* transaction finished */
  124. #define B_ERROR    0x00000004    /* transaction aborted */
  125. #define B_BUSY     0x00000008    /* not on av_forw/back list */
  126. #define B_PHYS     0x00000010    /* Physical IO */
  127. #define B_MAP      0x00000020    /* mappable data */
  128. #define B_WANTED   0x00000040    /* issue wakeup when BUSY goes off */
  129. #define B_AGE      0x00000080    /* delayed write for correct aging */
  130. #define B_ASYNC    0x00000100    /* don't wait for I/O completion */
  131. #define B_DELWRI   0x00000200    /* delayed write - wait until buffer needed */
  132. #define B_OPEN     0x00000400    /* open routine called */
  133. #define B_STALE    0x00000800
  134. #define B_LEADER   0x00001000    /* lead buffer in a list of them */
  135. #define B_FORMAT   0x00002000
  136. #define    B_PAGEIO   0x00004000    /* use b_pages for I/O */
  137. #define B_MAPPED   0x00008000    /* buffer has been mapped to kernel va */
  138. #define B_SWAP       0x00010000    /* block is on swap, paddr is physical addr */
  139. #define    B_BDFLUSH  0x00020000    /* block being written by bdflush() */
  140. #define B_RELSE       0x00040000    /* ignore b_relse field on brelse() */
  141. #define    B_PUSH     0x00080000    /* push through free list */
  142. #define    B_PARTIAL  0x00100000    /* buffer partially done, partially undone */
  143. #define    B_UNCACHED 0x00200000    /* uncached mapping requested for memcopy */
  144. #define    B_INACTIVE 0x00400000    /* buffer header taken out of cache to */
  145.                 /* reduce buffer cache memory use */
  146. #define    B_BFLUSH   0x00800000    /* delayed write buffer is being pushed out */
  147. #define B_FOUND    0x01000000    /* bp was found in cache (for stats) */
  148. #define B_WAIT       0x02000000    /* bp will be waited for after async push */
  149. #define B_WAKE       0x04000000    /* wake up page-waiters on b_relse */
  150. #define    B_HOLD       0x08000000    /* tell bwrite() not to unlock buffer */
  151. #define    B_DELALLOC 0x10000000    /* backing store reserved but not allocated */
  152. #define B_MAPUSER  0x20000000    /* buf address is user address */
  153. #define    B_DACCT       0x40000000    /* buf accounted for in dchunkxxx counters */
  154.  
  155. /*
  156.  *    These flags are kept in b_flags2.
  157.  */
  158. #define B_GR_BUF   0x00000001    /* bp is a guaranteed rate I/O */
  159. #define B_GR_Q     0x00000002   /* guraranteed rate I/O bp was queued */
  160. #define B_GR_ISD   0x00000004   /* guraranteed rate I/O bp was issued */
  161. #define B_GR_RSTRT 0x00000008   /* issue queued request */
  162. #define B_XLV_HBUF 0x00000010    /* initial request issued to xlv */
  163. #define    B_XLVD_BUF 0x00000020    /* buffer was allocated by xlvd */
  164. #define    B_XLVD_FAILOVER \
  165.            0x00000040    /* buffer is failing over */
  166. #define    B_XLV_IOC  0x00000080    /* io context has been allocated */
  167. #define    B_XLV_ACK  0x00000100    /* buffer requires ack */
  168. #define B_SHUFFLED 0x00000200   /* disk sched fairness already applied */
  169. #define B_PRIO_BUF 0x00000400    /* bp is a priority I/O bp */
  170. #define B_XFS_INO  0x00000800    /* bp contains XFS inodes */
  171. #define B_VDBUF       0x00010000    /* buffer accounted for in vnode's v_dbuf cnt */
  172.  
  173. #define BP_IS_PRIORITY(bp)    (bp->b_flags2 & B_PRIO_BUF)
  174.  
  175. #define BP_ISMAPPED(bp)    ((bp->b_flags & (B_PAGEIO|B_MAPPED)) != B_PAGEIO)
  176.  
  177. /*
  178.  * Flags for incore_match() and findchunk_match().
  179.  */
  180. #define    BUF_FSPRIV    0x1
  181. #define    BUF_FSPRIV2    0x2
  182.  
  183. #ifdef _KERNEL
  184.  
  185. #define bfree_lock(listid) \
  186.     mutex_spinlock((lock_t*)&bfreelist[(listid)].b_private)
  187. #define bfree_unlock(listid, s) \
  188.     mutex_spinunlock((lock_t *)&bfreelist[(listid)].b_private, s)
  189. #define nested_bfree_lock(listid) \
  190.     nested_spinlock((lock_t*)&bfreelist[(listid)].b_private)
  191. #define nested_bfree_unlock(listid) \
  192.     nested_mutex_spinunlock((lock_t*)&bfreelist[(listid)].b_private
  193.  
  194. #ifdef DEBUG
  195. void bfreelist_check(buf_t *);
  196. #else
  197. #define bfreelist_check(b)
  198. #endif
  199.  
  200. /*
  201.  *    Fast access to buffers in cache by hashing.
  202.  */
  203.  
  204. #define bhash(d,b)  ((buf_t *)&global_buf_hash[((int)(d)+(int)(b))&v.v_hmask])
  205.  
  206. typedef struct hbuf {
  207.     sema_t    b_lock;            /* lock for hash queue */
  208.     int    b_flags;
  209.     struct    buf    *b_forw;
  210.     struct    buf    *b_back;
  211. } hbuf_t;
  212.  
  213. extern    hbuf_t        *global_buf_hash;
  214.  
  215. #define    BIO_MAXBSIZE_LOG2    (BPCSHIFT+8)
  216. /* Limit for maximum offsets, in chars and BBs that can be reached via lseek */
  217.  
  218. #define    BIO_MAXBSIZE        (1<<BIO_MAXBSIZE_LOG2)
  219. #define    BIO_MAXBBS        (1<<(BIO_MAXBSIZE_LOG2-BBSHIFT))
  220. /*
  221.  * Hashing parameters.  Each disk block is scaled into a larger block,
  222.  * whose length is twice the maximun length of a buffer block.
  223.  * Maximum overlap of buckets is thus reduced to 2.
  224.  */
  225. #define    BIO_BBSPERBUCKETSHIFT    (5)
  226. #define    BIO_BBSPERBUCKETMINUSONE    ((1 << BIO_BBSPERBUCKETSHIFT) - 1)
  227. #define    BIO_BBSPERLBMINUSONE    (BTOBBT(BIO_MAXBSIZE) - 1)
  228.  
  229. /*
  230.  * The bwait_pin structure is used to wait for a buffer to be unpinned.
  231.  */
  232. typedef struct bwait_pin {
  233.     sv_t    bwp_wait;    /* buffer wait variable */
  234.     int    bwp_count;    /* wait counter */
  235. } bwait_pin_t;    
  236.  
  237. #define    NUM_BWAIT_PIN    32
  238. #define    BWAIT_PIN_MASK    (NUM_BWAIT_PIN - 1)
  239. /*
  240.  * This gets ugly in order to handle buffer allocated from the heap.
  241.  */
  242. #define    BPTOBWP(bp)    ((((bp) < &global_buf_table[0]) || \
  243.               ((bp) >= &global_buf_table[v.v_buf])) ? \
  244.              &bwait_pin[0] : \
  245.              &bwait_pin[((bp) - global_buf_table) & BWAIT_PIN_MASK])
  246.  
  247. extern bwait_pin_t    bwait_pin[];
  248.  
  249. /*
  250.  * Flags for get_buf() and read_buf().
  251.  */
  252. #define    BUF_TRYLOCK    0x00000001
  253. #define    BUF_BUSY    0x00000002
  254.  
  255. /*
  256.  * Flags for incore().
  257.  */
  258. #define    INCORE_LOCK    0x00000001
  259. #define    INCORE_TRYLOCK    0x00000002
  260.  
  261. /*
  262.  * Flags for chunk_decommission().
  263.  */
  264. #define    CD_FLUSH    0x1
  265.  
  266. /*
  267.  * Flags for chunktoss().
  268.  */
  269. #define    C_PUSH    0x01
  270. #define    C_EOF    0x02
  271.  
  272. /*
  273.  * Chunk tracing stuff.
  274.  */
  275. struct ktrace;
  276. extern struct ktrace    *buf_trace_buf;
  277.  
  278. #ifndef DEBUG
  279.  
  280. #define    buftrace(id, bp)
  281.  
  282. #else /* DEBUG */
  283.  
  284. #define buftrace(id, bp) \
  285.         buftrace_enter(id, bp, (inst_t *)__return_address)
  286. extern void    buftrace_enter(char *, buf_t *, inst_t *);
  287.  
  288. #endif /* DEBUG */
  289.  
  290. enum uio_rw;
  291. struct bmapval;
  292. struct cred;
  293. struct pfdat;
  294. struct uio;
  295. struct vnode;
  296. struct alenlist_s;
  297. struct iovec;
  298.  
  299. extern void    binit(void);
  300. extern buf_t    *incore_match(dev_t, daddr_t, int, int, void *);
  301. extern void    notavail(buf_t *);
  302. extern buf_t    *getblk(dev_t, daddr_t, int);
  303. extern buf_t    *get_buf(dev_t, daddr_t, int, uint);
  304. extern buf_t    *geteblk(void);
  305. extern int    geterror(buf_t *);
  306. extern buf_t    *getrbuf(int);
  307. extern buf_t    *ngetrbuf(size_t);
  308. extern buf_t    *ngeteblk(size_t);
  309. extern buf_t    *bread(dev_t, daddr_t, int);
  310. extern buf_t    *breada(dev_t, daddr_t, int, daddr_t, int);
  311. extern buf_t    *read_buf(dev_t, daddr_t, int, uint);
  312. extern void    baread(dev_t, daddr_t, int);
  313. extern int    bwrite(buf_t *);
  314. extern void    bdwrite(buf_t *);
  315. extern void    bawrite(buf_t *);
  316. extern void    brelse(buf_t *);
  317. extern void    binval(dev_t);
  318. extern void    bflush(dev_t);
  319. extern void    bpin(buf_t *);
  320. extern void    bunpin(buf_t *);
  321. extern void    bwait_unpin(buf_t *);
  322. extern int    iowait(buf_t *);
  323. extern void    iodone(buf_t *);
  324. extern int    biowait(buf_t *);
  325. extern void    biodone(buf_t *);
  326. extern void     bioerror(struct buf *, int);
  327. extern void    clrbuf(buf_t *);
  328. extern void    freerbuf(buf_t *);
  329. extern void    nfreerbuf(buf_t *);
  330. extern char    *bp_mapin(buf_t *);
  331. extern void    bp_mapout(buf_t *);
  332. extern struct pfdat    *getnextpg(buf_t *, struct pfdat *);
  333. extern caddr_t    maputokv(caddr_t, size_t, int);
  334. extern void    unmaputokv(caddr_t, size_t);
  335. extern int    iomap(buf_t *);
  336. extern int    iomap_vector(buf_t *, struct iovec *, int);
  337. extern void    iounmap(buf_t *);
  338. extern void    unuseracc(void *, size_t, int);
  339. extern void    fast_unuseracc(void *, size_t, int, opaque_t *);
  340. extern int    useracc(void *, size_t, int, void *);
  341. extern int    fast_useracc(void *, size_t, int, opaque_t *);
  342. extern int    userdma(void *, size_t, int, void *);
  343. extern int    fast_userdma(void *, size_t, int, opaque_t *);
  344. extern void    undma(void *, size_t, int);
  345. extern void    fast_undma(void *, size_t, int, opaque_t *);
  346. extern buf_t    *getphysbuf(void);
  347. extern int    uiophysio(int (*)(buf_t *), buf_t *, dev_t, int, struct uio *);
  348. extern int    biophysio(int (*)(buf_t *), buf_t *, dev_t, int, daddr_t,
  349.               struct uio *);
  350. extern void    putphysbuf(buf_t *);
  351. extern buf_t    *incore(dev_t, daddr_t, int, int);
  352. extern int    biomove(buf_t *, u_int, size_t, enum uio_rw, struct uio *);
  353. extern buf_t    *chunkread(struct vnode *, struct bmapval *,
  354.                int, struct cred *);
  355. extern buf_t    *getchunk(struct vnode *, struct bmapval *, struct cred *);
  356. extern buf_t    *chunkreread(buf_t *);
  357. extern void    dchunkunchain(buf_t *);
  358. extern void    delalloc_free(buf_t *);
  359. extern void    clusterwrite(buf_t *, clock_t);
  360. extern void    bp_dcache_wbinval(buf_t *);
  361. extern void    chunktoss(struct vnode *, off_t, off_t);
  362. extern int    chunkpush(struct vnode *, off_t, off_t, int);
  363. extern void    chunkinvalfree(struct vnode *);
  364. #ifdef TILE_DATA
  365. extern int    chunkpfind(struct pfdat *, buf_t **);
  366. extern int    chunkpreplace(buf_t *, struct pfdat *, struct pfdat *);
  367. #endif /* TILE_DATA */
  368.  
  369. #ifdef DEBUG
  370. extern void    bflushed(dev_t);
  371. #else
  372. #define    bflushed(dev)
  373. #endif
  374.  
  375. #endif    /* _KERNEL */
  376. #endif    /* __SYS_BUF_H__ */
  377.